/**
  ******************************************************************************
  * @file    PWM_LED.c
  * @brief   This file provides firmware functions to manage the LED
  ******************************************************************************
  
  
 */
 
 /* Includes ------------------------------------------------------------------*/
 
 #include "PWM_LED.h"
 
/* Private typedef -----------------------------------------------------------*/


/* Private define ------------------------------------------------------------*/
#define DEBUG_MODE 1
 
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/

void LED_init(){
	hled1->Speed = SPEED_LOW;
	hled1->Brightness=MODERATE;
	printf("LED_start");
}
LED_Brightness_t get_LED_brightness(volatile LED_HandleTypeDef  hled){
	if(hled.Brightness!= NULL){
      LED_Brightness_t LED_brightness=hled.Brightness;
	  return LED_brightness;
	}
}
LED_Speed_t get_LED_speed(volatile LED_HandleTypeDef *hled){
	if(hled->Speed != NULL){
		  LED_Speed_t LED_speed=hled->Speed;
		  return LED_speed;
	}
}
void LED_adjust_brightness(volatile LED_HandleTypeDef hled){
	if(hled.Brightness!= NULL){
			#if DEBUG_MODE
				printf("After_bright:%d",hled.Brightness );
			#endif
			uint16_t AUTORELOAD_VALUE=__HAL_TIM_GET_AUTORELOAD(&htim4);
			#if DEBUG_MODE
				printf("AUTORELOAD_VALUE:%d",AUTORELOAD_VALUE );
			#endif
			uint16_t Real_Brightness = hled.Brightness * AUTORELOAD_VALUE / 100 ;
			#if DEBUG_MODE
				printf("Real_Brightness:%d",Real_Brightness );
			#endif
	}
}
void LED_adjust_speed(volatile LED_HandleTypeDef *hled,LED_Speed_t Expected_Speed){
	if( hled->Speed != NULL){
		 if(hled->Speed != Expected_Speed){
			#if DEBUG_MODE
				printf("Expected_Speed:%d",Expected_Speed);
			#endif
			hled->Speed = Expected_Speed;
			#if DEBUG_MODE
				printf("After_Speed:%d",hled->Speed );
			#endif
		}
	}
}
void LED_speed_control(LED_HandleTypeDef *hled){
	if(hled != NULL){
		switch(hled->Speed){
		  case SPEED_LOW:
			HAL_Delay(50);
			break;
		  case SPEED_MODERATE:
			HAL_Delay(20);
			break;
		  case SPEED_HIGH:
			HAL_Delay(1);
			break;
		  default:
			HAL_Delay(20);
			break;
		}
		
	}
	else{
		printf("hled is NUll");
	}
}


